<?php

/**
 * 留言板
 */

class GuestbookAction extends HomeBaseAction{

    public function index(){

        $this->location = 'guestbook';

        $this->display();
    }

    public function handleAdd(){
        // p($_POST);
        // p($_SESSION);
        if($_POST['code'] != $_SESSION['guestbook']){
            echo -1;exit;
        }
        if(empty($_POST['name'])){
            echo -2;exit;
        }
        if(empty($_POST['content'])){
            echo -3;exit;
        }

        $data['name'] = I('post.name');
        $data['email'] = I('post.email');
        $data['phone'] = I('post.phone');
        $data['qq'] = I('post.qq');
        $data['content'] = I('post.content');
        $data['ip'] = get_client_ip();
        $data['create_time'] = time();
        
        $res = M('guestbook')->add($data);
        if($res){
            echo 1;exit;
        }else{
            echo -4;
        }
    }

    public function lists(){
        $this->location = 'guestbook_list';
        $this->display();
    }

}